CC	= gcc
AS	= nasm
RM	= rm -f
CFLAGS	= -nostdlib -nostdinc -fno-builtin -fno-stack-protector -m32 -g -O0
CPPFLAGS= -I../include
ASFLAGS = -felf

SOURCES	= dt.c main.c timer.c trap.c isr.c
ASMFILE	= paging.s dt_asm.s 8259.s int.s

build: $(SOURCES) asbuild
	$(CC) $(CFLAGS) $(CPPFLAGS) -c $(SOURCES)

clean:
	$(RM) *.o *.d

asbuild:
	for f in $$(ls *.s);\
	do \
	$(AS) $(ASFLAGS) $$f ;\
	done;

%.d: %.c
	$(CC) -M $(CPPFLAGS) $< > $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$
include $(subst .c,.d,$(SOURCES))
